from django.db import models


# Create your models here.

class User(models.Model):
    user_name = models.CharField(max_length=20)
    user_pwd = models.CharField(max_length=30)
    user_email = models.EmailField(unique=True)
    user_authority = models.BooleanField(default=False)


class Communicator(models.Model):
    communicator_id = models.CharField(max_length=8)
    communicator_info = models.CharField(max_length=100)
    communicator_state = models.CharField(max_length=10)
    user_name = models.ForeignKey(User, on_delete=models.CASCADE)


class Terminal(models.Model):
    terminal_id = models.CharField(max_length=1)
    terminal_info = models.CharField(max_length=100)
    terminal_state = models.CharField(max_length=10)
    communicator = models.ForeignKey(Communicator, on_delete=models.CASCADE, related_name="com")


class DateData(models.Model):
    communicator_id = models.CharField(max_length=8)
    terminal_id = models.CharField(max_length=1)
    terminal_db = models.ForeignKey(Terminal, on_delete=models.CASCADE)
    record_time = models.DateTimeField()
    sys_state = models.CharField(max_length=8)
    en_state = models.CharField(max_length=2)
    mode = models.CharField(max_length=4)
    power_produce = models.IntegerField(default=0)
    net_voltage_a = models.IntegerField()
    net_voltage_b = models.IntegerField()
    net_frequence = models.IntegerField()
    mechine_voltage_a = models.IntegerField()
    mechine_voltage_b = models.IntegerField()
    mechine_frequence = models.IntegerField()
    mechine_current_a = models.IntegerField()
    mechine_current_b = models.IntegerField()
    mechine_current_c = models.IntegerField()
    useful_power = models.IntegerField()
    useless_power = models.IntegerField()
    power_factor = models.IntegerField()
    excite_voltage = models.IntegerField()
    excite_current = models.IntegerField()
    water_level = models.IntegerField()
    increase_state = models.CharField(max_length=3)
    decrease_state = models.CharField(max_length=3)
    battery = models.IntegerField()
    temperature = models.IntegerField()
